<template>
  <div class="order-wrapper">
    <div class="search-container">
      <div class="order-num-container search-item">
        <div class="title">订单号：</div>
        <el-input v-model="order_no" type="text" placeholder="请输入订单号" class="input-container" />
      </div>
      <div class="order-num-container search-item">
        <div class="title">时间：</div>
        <el-date-picker
          v-model="timer"
          type="datetimerange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </div>
      <el-button type="primary" class="search-button" @click="handleSearch">搜索</el-button>
    </div>
    <el-table ref="multipleTable" v-loading="loading" :data="tableData" border tooltip-effect="dark" style="width: 100%">
      <el-table-column prop="order_no" label="订单号" min-width="200" />
      <el-table-column prop="amount" label="储值总额（元）" min-width="150" />
      <el-table-column prop="give_amount" label="赠送总额（元）" min-width="150" />
      <el-table-column prop="payment" label="支付方式" min-width="100">
        <template slot-scope="scope">
          <el-tag v-if="scope.row.payment === 'wepay'" type="success">微信</el-tag>
          <el-tag v-if="scope.row.payment === 'alipay'" type="success">支付宝</el-tag>
          <el-tag v-if="scope.row.payment === 'balance'" type="success">余额</el-tag>
          <el-tag v-if="scope.row.payment === 'deposit'" type="success">储值</el-tag>
          <el-tag v-if="scope.row.payment === 'consume'" type="success">消费额</el-tag>
          <el-tag v-if="scope.row.payment === 'blessing'" type="success">待反金</el-tag>
          <el-tag v-if="scope.row.payment === 'combined'" type="success">组合支付</el-tag>
        </template>
      </el-table-column>
      <el-table-column prop="pay_at" label="支付时间" min-width="100" />
    </el-table>
    <pagination v-show="total>listQuery.limit" :total="total" :page.sync="listQuery.page" :limit.sync="listQuery.limit" @pagination="getList" />
  </div>
</template>

<script>
import { storevalueOrder } from '@/api/order'
import Pagination from '@/components/Pagination'
import { parseTime } from '@/utils'
export default {
  name: 'OrderList',
  components: {
    Pagination
  },
  props: {
    type: {
      type: Number,
      default: 0
    }
  },
  data() {
    return {
      loading: false,
      order_no: '',
      username: '',
      total: 0,
      phone: '',
      listQuery: {
        page: 1,
        limit: 10
      },
      list: [],
      timer: []
    }
  },
  computed: {
    tableData() {
      return this.list.map((item) => {
        item.pay_at = item.pay_at ? parseTime(item.pay_at) : ''
        item.desc = item.desc ? item.desc : ''
        return item
      })
    }
  },
  created() {
    this.initList()
  },
  methods: {
    // 分页
    getList(prop) {
      this.listQuery.page = prop.page
      this.listQuery.limit = prop.limit
      this.initList()
    },
    async initList() {
      this.loading = true
      const { uid } = this.$route.query
      const { order_no, timer } = this
      const start_time = timer.length ? Math.round(+new Date(timer[0]) / 1000) : ''
      const end_time = timer.length ? Math.round(+new Date(timer[1]) / 1000) : ''
      const { page, limit } = this.listQuery
      const res = await storevalueOrder({ uid, order_no, page, limit, start_time, end_time })
      this.loading = false
      const { total, lists } = res.data
      this.total = total
      this.list = lists
    },
    handleSearch() {
      this.initList()
    }
  }
}
</script>

<style lang="scss" scoped>
.order-wrapper {
  position: absolute;
  top: 10px;
  left: 0;
  right: 0;
  bottom: 0;
  background: #fff;
  padding: 20px;
  box-sizing: border-box;
  .search-container{
    width: 100%;
    display: flex;
    flex-wrap: wrap;
    margin-bottom: 20px;
    .search-item {
      display: flex;
      align-items: center;
      margin-right: 20px;
      .title {
        width: 80px;
      }
      .input-container{
        width: 200px;
      }
    }
  }
}
</style>
